<?php


namespace App\Http\Middleware;


use App\Service\Constant;
use Closure;
use Illuminate\Http\Request;

class Token
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle(Request $request, Closure $next)
    {
        $token = $request->header('token');
        $id = \App\Server\Token::check($token);
        if (!$id) {
            return response()->json([
                'status' => 0,
                'code' => 401,
                'msg' => '请先登录',
                'data' => []
            ]);
        }

        $request->uid = $id;

        return $next($request);
    }
}